package com.javapowertools.taxcalculator;

public class TaxRate {
	private double minimumRevenue;
	private double maximumRevenue;
	private double rate;

	public TaxRate(double minimumRevenue, double maximumRevenue, double rate) {
		this.minimumRevenue = minimumRevenue;
		this.maximumRevenue = maximumRevenue;
		this.rate = rate;
	}

	private double getApplicableAmount(double totalRevenue) {
		double applicableAmount = 0.0d;

		if (totalRevenue >= minimumRevenue) {
			applicableAmount = totalRevenue - minimumRevenue;
			if (maximumRevenue > 0 && totalRevenue > maximumRevenue) {
				applicableAmount = maximumRevenue - minimumRevenue;
			}
		}
		return applicableAmount;
	}

	public double calculateTax(double totalRevenue) {
		return getApplicableAmount(totalRevenue) * rate;
	}

	public double getMinimumRevenue() {
		return minimumRevenue;
	}

	public void setMinimumRevenue(double minimumRevenue) {
		this.minimumRevenue = minimumRevenue;
	}

	public double getMaximumRevenue() {
		return maximumRevenue;
	}

	public void setMaximumRevenue(double maximumRevenue) {
		this.maximumRevenue = maximumRevenue;
	}

	public double getRate() {
		return rate;
	}

	public void setRate(double rate) {
		this.rate = rate;
	}

}
